﻿using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using CCTool.Scripts.Manager;
using CCTool.Scripts.ToolManagers;
using CCTool.Scripts.ToolManagers.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CCTool.Scripts.DataPross.FeatureClasses
{
    /// <summary>
    /// Interaction logic for SearchNarrow.xaml
    /// </summary>
    public partial class SearchNarrow : ArcGIS.Desktop.Framework.Controls.ProWindow
    {
        public SearchNarrow()
        {
            InitializeComponent();
        }

        // 定义一个进度框
        private ProcessWindow processwindow = null;
        string tool_name = "查找狭长面";

        private void combox_fc_DropDown(object sender, EventArgs e)
        {
            UITool.AddFeatureLayersToComboxPlus(combox_fc);
        }

        private async void btn_go_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // 获取参数
                string def_gdb = Project.Current.DefaultGeodatabasePath;    // 工程默认数据库

                string in_fc = combox_fc.ComboxText();

                // 打开进度框
                ProcessWindow pw = UITool.OpenProcessWindow(processwindow, tool_name);
                pw.AddMessageTitle(tool_name);

                Close();

                await QueuedTask.Run(() =>
                {
                    pw.AddMessageStart($"计算形状参数");
                    // 添加字段
                    string field = "XCCS";
                    if (!GisTool.IsHaveFieldInTarget(in_fc, field))
                    {
                        Arcpy.AddField(in_fc, field, "DOUBLE");
                    }

                    // 计算形状参数
                    string block = "(!shape!.area*3.1415926*4)/(!shape!.length*!shape!.length)";
                    Arcpy.CalculateField(in_fc, field, block);
                  
                });

                pw.AddMessageEnd();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message + ee.StackTrace);
                return;
            }
        }

        private void btn_help_Click(object sender, RoutedEventArgs e)
        {
            string url = "https://blog.csdn.net/xcc34452366/article/details/149608151";
            UITool.Link2Web(url);
        }
    }
}
